package com.hnxxxy.workshop.controller;


import com.hnxxxy.workshop.request.*;
import com.hnxxxy.workshop.service.WorkerService;
import com.hnxxxy.workshop.utils.R;
import com.hnxxxy.workshop.vo.DepotVO;
import com.hnxxxy.workshop.vo.WorkerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 工人 前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/worker")
@Api(value = "WorkerController", tags = {"工人模块"})
public class WorkerController {
    @Resource
    private WorkerService workerService;

    @PostMapping("/add")
    @ApiOperation(value = "创建工人")
    public R add(@ApiParam("工人对象") @RequestBody WorkerRequest workerRequest){
        workerService.add(workerRequest);
        return R.buildSuccess();
    }

    @GetMapping("/remove/{id}")
    @ApiOperation(value = "删除工人")
    public R deleteById(@ApiParam(value = "工人id",required = true)
                        @PathVariable("id") int id){
        workerService.deleteById(id);
        return R.buildSuccess();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改工人")
    public R update( @ApiParam("工人对象")
                     @RequestBody WorkerRequest workerRequest){
        workerService.update(workerRequest);
        return R.buildSuccess();
    }

    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据id查询工人信息")
    public R findByIdWorker(@ApiParam(value = "工人id",required = true)
                           @PathVariable("id") int id ){
        WorkerVO workerVO = workerService.findByIdWorker(id);
        return R.buildSuccess(workerVO);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询全部工人")
    public R findByIdFactory(@ApiParam(value = "分页对象",required = true)
                             @RequestBody WorkerPageRequest workerPageRequest){
        Map<String,Object> pageResult = workerService.page(workerPageRequest);
        return R.buildSuccess(pageResult);
    }

}

